const BASE_URL = 'https://www.example.com/request'; //仅为示例，并非真实接口地址。

export const request = (config = {}) => {
	let {
		url,
		method = 'GET',
		data = {},
		header = {},
		isLoading = true
	} = config
	url = BASE_URL + url;
	header['token'] = '11';


	return new Promise((resolve, reject) => {
		if (isLoading) {
			uni.showLoading({
				title: '加载中...'
			})
		}
		uni.request({
			url,
			method,
			data,
			header,
			success: (res) => {
				// 判断状态码
				if (res.data.errCode = 0) {
					resolve(res)
				} else if (res.data.errCode === 400) {
					uni.showModal({
						title： "错误提示"，
						content: res.data.errMsg,
						showCancel: false
					})
					reject(res.data)
				} else {
					uni.showToast({
						title: res.data.errMsg,
						icon: "none"
					})
				}
			},
			fail: (err) => {
				reject(err)
			},
			complete: () => {
				uni.hideLoading()
			}
		});
	})

}